//
//  Match.m
//  NJYouthOlypic
//
//  Created by Xiu on 6/27/13.
//  Copyright (c) 2013 Xiu. All rights reserved.
//

#import "Match.h"
#import "MatchCategory.h"

@implementation Match

+ (NSArray*)defaultMatcheCategories{
  NSString* plistFile = [[NSBundle mainBundle] pathForResource:@"DefaultMatches" ofType:@"plist"];
  NSArray* matchesSource = [[NSArray alloc] initWithContentsOfFile:plistFile];
  NSMutableArray* matches = [NSMutableArray array];
  for (NSDictionary* matchDict in matchesSource) {
    MatchCategory* match = [[MatchCategory alloc] initWithDictionary:matchDict];
    [matches addObject:match];
  }
  return matches;
}


- (id)initWithDictionary:(NSDictionary*)matchDict{
  self = [super init];
  if (nil == self) {
    return nil;
  }
  self.type = MatchTypeMatch;
  self.info = matchDict;
  self.matchId = [matchDict objectForKey:@"id"];
  self.content = [matchDict objectForKey:@"content"];
  self.place = [matchDict objectForKey:@"place"];
  self.title = [matchDict objectForKey:@"title"];
  
  NSString* time = [matchDict objectForKey:@"time"];
  NSString* dateStr = [[time componentsSeparatedByString:@" "] objectAtIndex:0];
  NSString* timestampStr = [[time componentsSeparatedByString:@" "] objectAtIndex:1];
  NSString* startTimeStamp = [[timestampStr componentsSeparatedByString:@"-"] objectAtIndex:0];
  NSString* endTimeStamp = [[timestampStr componentsSeparatedByString:@"-"] objectAtIndex:0];
  NSString* startDateStr = [NSString stringWithFormat:@"%@ %@",dateStr,startTimeStamp];
  NSString* endDateStr = [NSString stringWithFormat:@"%@ %@",dateStr,endTimeStamp];
  

  
  NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
  [formatter setDateFormat:@"yyyyMMdd HH:mm"];
  self.startDate = [formatter dateFromString:startDateStr];
  self.endDate = [formatter dateFromString:endDateStr];
  
  return self;
}



@end
